import type { ApiType} from 'src/service/api';
import { mainSearchArticle } from 'src/service/api';
import { ref } from 'vue';

export type rowsType = ApiType<typeof mainSearchArticle>['Return']['rows'][0];

export const rows = ref<Array<rowsType>>([]);

export const pageParam = ref({
  pageNum: 1,
  pageSize: 20,
  totalPage: 0,
  recordCount: 0,
  text: '',
  order: 'read_num',
});

export const loading = ref(false);

export const f5 = async () => {
  rows.value = [];
  loading.value = true;
  const { data, error } = await mainSearchArticle(pageParam.value);
  loading.value = false;
  if (!error) {
    pageParam.value.totalPage = data.totalPage;
    pageParam.value.recordCount = data.recordCount;
    rows.value = data.rows;
  }
};
